package com.sinodata.ns.versions;

import jt.classic.system.wordbook.WordBookUtil;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import org.limp.basework.impl.CommonBean4HSQ;

import org.limp.mine.XMLTool;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class Versions extends DispatchAction {
    public ActionForward checkVersion(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {
        Map resultMap = new HashMap();
        resultMap.put("opera", "checkVersion");
        try {
            CommonBean4HSQ cbh = new CommonBean4HSQ(request);

            Map param = cbh.getResource();

            String ver = (String) param.get("ver");

            String type = "mobileVersion";
            String version = WordBookUtil.getWordBookItemName(type, "version");
            String url = WordBookUtil.getWordBookItemName(type, "downloadurl");
            String describe = WordBookUtil.getWordBookItemName(type, "describe");
            System.out.println(version);
            
            if (version.equals(ver)) {
                resultMap.put("verStt", "0");
                resultMap.put("url", "");
            } else {
                resultMap.put("verStt", "1");
                resultMap.put("url",url);
            }
        } catch (Exception e) {
            resultMap.put("status", "1");
            resultMap.put("verStt", "");
            resultMap.put("url", "");
        }

        resultMap.put("status", "0");

        String result = XMLTool.result2XML(resultMap);

        request.setAttribute("result", result);
        return mapping.findForward("result");
    }
}
